//
//  AppDelegate.m
//  UI-02-登录界面
//
//  Created by dllo on 16/6/6.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()<UITextFieldDelegate>
@property (nonatomic, retain) UIView *loginView; // 登录
@property (nonatomic, retain) UIView *forgetView; // 找回
@property (nonatomic, retain) UIView *registerView; // 注册

@end

@implementation AppDelegate
- (void)dealloc{
    [_window release];
    [super dealloc];
}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    self.window.rootViewController = [[UIViewController alloc]init];
    
    //找回页面
    self.forgetView = [[UIView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    self.forgetView.backgroundColor = [UIColor whiteColor];
    [self.window addSubview:self.forgetView];
    self.forgetView.tag = 1000;
    [self.forgetView release];
    
    //邮箱输入框
    UITextField *emailTextView = [[UITextField alloc]initWithFrame:CGRectMake(80, 120, self.forgetView.frame.size.width - 160, 50)];
    emailTextView.backgroundColor = [UIColor whiteColor];
    emailTextView.layer.cornerRadius = 10;
    emailTextView.layer.borderWidth = 1;
    emailTextView.layer.borderColor = [UIColor cyanColor].CGColor;
    emailTextView.placeholder = @" 电子邮箱";
    emailTextView.delegate = self;  // 签订代理人
    emailTextView.clearButtonMode = UITextFieldViewModeAlways;
    [self.forgetView addSubview:emailTextView];
    [emailTextView release];
    
    //左侧button
    UIButton *emileLeftButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    emileLeftButton.frame = CGRectMake(100, 210, 80, 50);
    [emileLeftButton setTitle:@"找回" forState:(UIControlStateNormal)];
    emileLeftButton.titleLabel.font = [UIFont systemFontOfSize:22];
    [emileLeftButton addTarget:self action:@selector(click:) forControlEvents:(UIControlEventTouchUpInside)];
    emileLeftButton.tag = 1001;
    [self.forgetView addSubview:emileLeftButton];
    
    //右侧button
    UIButton *emileRightButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    emileRightButton.frame = CGRectMake(200, 210, 80, 50);
    [emileRightButton setTitle:@"取消" forState:(UIControlStateNormal)];
    emileRightButton.titleLabel.font = [UIFont systemFontOfSize:22];
    [emileRightButton addTarget:self action:@selector(click:) forControlEvents:(UIControlEventTouchUpInside)];
    emileRightButton.tag = 1002;
    [self.forgetView addSubview:emileRightButton];
    
    //登陆页面
    self.loginView = [[UIView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    self.loginView.backgroundColor = [UIColor whiteColor];
    [self.window addSubview: self.loginView];
    self.loginView.tag = 1003;
    [self.loginView release];
    
    //用户名label
    UILabel *userNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(40, 100, 100, 50)];
    userNameLabel.text = @"用户名";
    userNameLabel.font = [UIFont systemFontOfSize:22];
    [self.loginView addSubview:userNameLabel];
    [userNameLabel release];
    
    //密码label
    UILabel *passwordLabel = [[UILabel alloc ]initWithFrame:CGRectMake(40, 180, 100, 50) ];
    passwordLabel.text = @"密码";
    passwordLabel.font = [UIFont systemFontOfSize:22];
    [self.loginView addSubview:passwordLabel];
    [passwordLabel release];
    
    //用户名textField
    UITextField *userNameTextField = [[UITextField alloc]initWithFrame:CGRectMake(140, 100, 200, 50)];
    userNameTextField.layer.cornerRadius = 10;
    userNameTextField.layer.borderWidth = 1;
    userNameTextField.clearButtonMode = UITextFieldViewModeAlways;
    userNameTextField.layer.borderColor = [UIColor colorWithRed:228/255. green:229/255. blue:230/255. alpha:1].CGColor;
    userNameTextField.delegate = self;
    userNameTextField.clearButtonMode = UITextFieldViewModeAlways;
    [self.loginView addSubview: userNameTextField];
    [userNameTextField release];
    
    //密码textField
    UITextField *passwordTextField = [[UITextField alloc]initWithFrame:CGRectMake(140, 180, 200, 50)];
    passwordTextField.backgroundColor = [UIColor whiteColor];
    passwordTextField.layer.cornerRadius = 10;
    passwordTextField.layer.borderWidth = 1;
    passwordTextField.layer.borderColor = [UIColor colorWithRed:228/255. green:229/255. blue:230/255. alpha:1].CGColor;
    passwordTextField.clearButtonMode = UITextFieldViewModeAlways;
    passwordTextField.delegate = self;
    passwordTextField.secureTextEntry = YES;  //安全文本
    passwordTextField.clearButtonMode = UITextFieldViewModeAlways;
    [self.loginView addSubview: passwordTextField];
    [passwordTextField release];
    
    //登录button
    UIButton *loginButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    [loginButton setTitle:@"登录" forState:(UIControlStateNormal)];
    loginButton.titleLabel.font = [UIFont systemFontOfSize:22];
    loginButton.frame = CGRectMake(40, 250, 90, 40);
    loginButton.tag = 1004;
    [loginButton addTarget:self action:@selector(click:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.loginView addSubview:loginButton];
    
    //找回密码button
    UIButton *passwordButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    [passwordButton setTitle:@"找回密码" forState:(UIControlStateNormal)];
    passwordButton.titleLabel.font = [UIFont systemFontOfSize:22];
    passwordButton.frame = CGRectMake(120, 250, 150, 40);
    passwordButton.tag = 1005;
    [passwordButton addTarget:self action:@selector(click:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.loginView addSubview: passwordButton];
    
    //注册button
    UIButton *registeredbButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    [registeredbButton setTitle:@"注册" forState:(UIControlStateNormal)];
    registeredbButton.titleLabel.font = [UIFont systemFontOfSize:22];
    registeredbButton.frame = CGRectMake(260, 250, 90, 40);
    registeredbButton.tag = 1006;
    [registeredbButton addTarget:self action:@selector(click:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.loginView addSubview: registeredbButton];
    
    //注册页面
    self.registerView = [[UIView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    self.registerView.backgroundColor = [UIColor whiteColor];
    [self.window addSubview:self.registerView];
    self.registerView.tag = 1007;
    [self.registerView release];
    
    //用户名
    UILabel *userLabel = [[UILabel alloc]initWithFrame:CGRectMake(40, 80, 100, 50)];
    userLabel.text = @"用户名";
    userLabel.font = [UIFont systemFontOfSize:22];
    [self.registerView addSubview: userLabel];
    [userLabel release];
    
    UITextField *userTextField = [[UITextField alloc]initWithFrame:CGRectMake(160, 80, 200, 50)];
    userTextField.layer.cornerRadius = 10;
    userTextField.layer.borderWidth = 1;
    userTextField.layer.borderColor = [UIColor colorWithRed:228/255. green:229/255. blue:230/255. alpha:1].CGColor;
    userTextField.placeholder = @" 请输入用户名";
    userTextField.delegate = self;
    userTextField.clearButtonMode = UITextFieldViewModeAlways;
    [self.registerView addSubview: userTextField];
    [userTextField release];
    //密码
    UILabel *passWordLabel = [[UILabel alloc]initWithFrame:CGRectMake(40, 150, 100, 50)];
    passWordLabel.text = @"密码";
    passWordLabel.font = [UIFont systemFontOfSize:22];
    [self.registerView addSubview:passWordLabel];
    [passWordLabel release];
    
    UITextField *passWordTextField = [[UITextField alloc]initWithFrame:CGRectMake(160, 150, 200, 50)];
    passWordTextField.layer.cornerRadius = 10;
    passWordTextField.layer.borderWidth = 1;
    passWordTextField.layer.borderColor = [UIColor colorWithRed:228/255. green:229/255. blue:230/255. alpha:1].CGColor;
    passWordTextField.secureTextEntry = YES;
    passWordTextField.placeholder = @" 请输入密码";
    passWordTextField.delegate = self;
    passWordTextField.clearButtonMode = UITextFieldViewModeAlways;
    [self.registerView addSubview:passWordTextField];
    [passWordTextField release];
    
    //确认
    UILabel *confirmLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, 220, 100, 50)];
    confirmLabel.text = @"确认密码";
    confirmLabel.font = [UIFont systemFontOfSize:22];
    [self.registerView addSubview:confirmLabel];
    [confirmLabel release];
    
    UITextField *confirmTextField = [[UITextField alloc]initWithFrame:CGRectMake(160, 220, 200, 50)];
    confirmTextField.layer.cornerRadius = 10;
    confirmTextField.layer.borderWidth = 1;
    confirmTextField.layer.borderColor = [UIColor colorWithRed:228/255. green:229/255. blue:230/255. alpha:1].CGColor;
    confirmTextField.delegate = self;
    confirmTextField.placeholder = @" 再次输入密码";
    confirmTextField.secureTextEntry = YES;
    [self.registerView addSubview:confirmTextField];
    confirmTextField.clearButtonMode = UITextFieldViewModeAlways;  //清除按钮
    [confirmTextField release];
    
    //手机
    UILabel *phoneLabel = [[UILabel alloc]initWithFrame:CGRectMake(40, 290, 100, 50)];
    phoneLabel.text = @"手机号";
    phoneLabel.font = [UIFont systemFontOfSize:22];
    [self.registerView addSubview: phoneLabel];
    [phoneLabel release];
    
    UITextField *phoneTextField = [[UITextField alloc] initWithFrame:CGRectMake(160, 290, 200, 50)];
    phoneTextField.layer.cornerRadius = 10;
    phoneTextField.layer.borderWidth = 1;
    phoneTextField.layer.borderColor =[UIColor colorWithRed:228/255. green:229/255. blue:230/255. alpha:1].CGColor;
    phoneTextField.placeholder = @" 请输入联系方式";
    phoneTextField.delegate = self;
    phoneTextField.clearButtonMode = UITextFieldViewModeAlways;
    [self.registerView addSubview:phoneTextField];
    [phoneTextField release];
    
    //邮箱
    UILabel *emileLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, 360, 100, 50)];
    emileLabel.text = @"邮箱";
    emileLabel.font = [UIFont systemFontOfSize:22];
    [self.registerView addSubview:emileLabel];
    [emileLabel release];
    
    UITextField *emileTextField = [[UITextField alloc]initWithFrame:CGRectMake(160, 360, 200, 50)];
    emileTextField.layer.cornerRadius = 10;
    emileTextField.layer.borderWidth = 1;
    emileTextField.layer.borderColor =[UIColor colorWithRed:228/255. green:229/255. blue:230/255. alpha:1].CGColor;
    emileTextField.placeholder = @" 请输入邮箱";
    emileTextField.delegate = self;
    emileTextField.clearButtonMode = UITextFieldViewModeAlways;
    [self.registerView addSubview:emileTextField];
    [emileTextField release];
    
    //注册button
    UIButton *registeredbBtn = [[UIButton alloc]initWithFrame:CGRectMake(70, 450, 100, 50)];
    [registeredbBtn setTitle:@"注册" forState:(UIControlStateNormal)];
    [registeredbBtn setTitleColor:[UIColor colorWithRed:47/255. green:110/255. blue:163/255. alpha:1] forState:(UIControlStateNormal)];
    registeredbBtn.titleLabel.font = [UIFont systemFontOfSize:22];
    registeredbBtn.tag =1008;
    [registeredbBtn addTarget:self action:@selector(click:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.registerView addSubview:registeredbBtn];
    
    //取消Button
    UIButton *cencelButton = [[UIButton alloc]initWithFrame:CGRectMake(210, 450, 100, 50)];
    [cencelButton setTitle:@"取消" forState:(UIControlStateNormal)];
    [cencelButton setTitleColor:[UIColor colorWithRed:47/255. green:110/255. blue:163/255. alpha:1] forState:(UIControlStateNormal)];
    cencelButton.titleLabel.font = [UIFont systemFontOfSize:22];
    [cencelButton addTarget:self action:@selector(click:) forControlEvents:(UIControlEventTouchUpInside)];
    cencelButton.tag = 1009;
    [self.registerView addSubview:cencelButton];
    
    
    [_window release];



    return YES;
}

//点击return回收键盘的方法
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return YES;
}

//button的点击方法
-(void)click:(UIButton *)button{
    
    if (button.tag == 1001) {
        NSLog(@"找回成功");
    }else if(button.tag == 1004){
        NSLog(@"登陆成功");
    }else if (button.tag == 1008){
        NSLog(@"注册成功");
    }else if (button.tag == 1009){
        NSLog(@"1009");
        UIView *tempView = [self.window viewWithTag:1003];
        [self.window bringSubviewToFront:tempView];
    }else if (button.tag == 1005){
        NSLog(@"1005");
        UIView *tempView = [self.window viewWithTag:1000];
        [self.window bringSubviewToFront:tempView];
    }else if (button.tag == 1006){
        NSLog(@"1006");
        UIView *tempView = [self.window viewWithTag:1007];
        [self.window bringSubviewToFront:tempView];
    }else if (button.tag == 1002){
        NSLog(@"1002");
        UIView *tempView = [self.window viewWithTag:1003];
        [self.window bringSubviewToFront:tempView];
    }
}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
